---
title: Hooks
sidebar_label: hooks
---

DevSpace allows you to define execution of custom commands during certain lifecycle events. This makes it possible to customize the deployment and development process with DevSpace.

Hooks can be defined in the `hooks` section of `devspace.yaml`:
```yaml
hooks:
- command: echo
  args:
    - before image building
  when:
    before:
      images: all
```

:::note Example Project
For a complete example take a look at [this example project on GitHub](https://github.com/loft-sh/devspace/tree/main/examples/hooks).
:::

This tells DevSpace to execute the command `echo before image building` before any image will be built. You are able to define hooks for the following life cycle events:
- **before image building**: Will be executed before building any images. Value: `when.before.images: all`
- **after image building**: Will be executed after images have been successfully built. Value: `when.after.images: all`
- **before deploying**: Will be executed before any deployment is deployed. Value: `when.before.deployments: all`
- **after deploying**: Will be executed after all deployments are deployed. Value: `when.after.deployments: all`
- **before certain deployment**: Will be executed before a certain deployment is deployed.  Value: `when.before.deployments: my-deployment`
- **after certain deployment**: Will be executed after a certain deployment is deployed.  Value: `when.after.deployments: my-deployment`

:::info Errors in Hooks
If any hook returns a non zero exit code, DevSpace will abort and print an error message.
:::
